package com.example.thirdstage_project.service.impl;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.thirdstage_project.dao.UserDao;
import com.example.thirdstage_project.entity.Unit;
import com.example.thirdstage_project.entity.User;
import com.example.thirdstage_project.ov.LoginVO;
import com.example.thirdstage_project.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;


@Service
public class UserServiceImpl extends ServiceImpl<UserDao,User> implements UserService {
    @Autowired
    private UserDao userDao;


    @Override
    public User login1(Wrapper<User> queryWrapper) {
        return userDao.selectOne(queryWrapper);
    }

    @Override
    public User login2(String username, String password) {
        return userDao.login(username,password);
    }

    @Override
    public List<User> getAll() {
        return userDao.selectList(null);
    }

    @Override
    public boolean delete(Integer uid){
        return userDao.deleteByUid(uid)>0;
    }

    @Override
    public boolean save(User user) {
        return userDao.save(user)>0;
    }

    @Override
    public IPage<User> getPage(int currentPage, int pageSize) {
        IPage page = new Page(currentPage,pageSize);
        userDao.selectPage(page,null);
        return page;
    }

    @Override
    public boolean updateById(User user) {
        return userDao.updateById(user)>0;
    }

    @Override
    public List<LoginVO> listByName() {
        return userDao.listByName();
    }

    @Override
    public boolean updatePassword(String password) {
        return userDao.updatePassword(password)>0;
    }

    @Override
    public boolean updateOption(String username, String password, int gid) {
        return userDao.updateOption(username,password,gid)>0;
    }

    @Override
    public boolean updateEx(Unit unit) {
        return userDao.updateEx(unit)>0;
    }
}
